package com.tj.admin.rest.product;

import com.fqgj.common.api.Page;
import com.qianli.cashmama.product.facade.result.ProductCategory;
import com.tj.admin.auth.anno.VisitorAccessible;
import com.tj.admin.auth.request.AddProductRequest;
import com.tj.admin.auth.request.EditorProductRequest;
import com.tj.admin.auth.service.ProductApplication;
import com.tj.admin.auth.vo.ProductInfoVo;
import com.tj.admin.auth.response.ProductListDTO;
import com.tj.bo.common.conf.api.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.Query;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/productold")
public class ProductControllerOld {


    @Autowired
    private ProductApplication productApplication;

    @RequestMapping(value = "/list")
    @VisitorAccessible
    @Query
    public ApiResponse<ProductListDTO> list(int currentPage, String productName) {
        Page page = new Page();
        page.setCurrentPage(currentPage);
        page.setPageSize(50);
        ApiResponse<ProductListDTO> response = productApplication.queryProductList(page, productName);
        return response;
    }

    @RequestMapping(value = "/add")
    @VisitorAccessible
    public ApiResponse<ProductListDTO> add(@RequestBody AddProductRequest body) {
        productApplication.addProduct(body);
        return new ApiResponse<>();
    }

    @RequestMapping(value = "/editor")
    @VisitorAccessible
    public ApiResponse<ProductListDTO> editor(@RequestBody EditorProductRequest body) {
        productApplication.editorProduct(body);
        return new ApiResponse<>();
    }
}
